require(["jquery",'public','weui'],function($,public,weui) {
    //public.headertitle("请输入内容搜索");
    //public.footer(4);
    public.allocator();

    //页面加载完毕
    public.loaded();

    //清空搜索栏
    $('[name="search"]').val('');

    //搜索历史
    var _history = window.localStorage.getItem('searchList') || null;
    var history = [];
    var historyJson = {};
    if(_history){
    	history =  _history.split(',');
    }
    var search_list = '';
    history.forEach(function(i){
    	historyJson[i] = i;
    	search_list += '<dd class="bx4"><a class="search_link" href="'+MODULE+'PublicJump/searchList/search/'+i+'">'+i+'</a></dd>';
    });
    if(search_list != ''){
    	$('.history_search').removeClass('hide');
    	$('.search_list').html(search_list);
    }else{
        $('.search_msg').removeClass('hide');
    }
    
    //清空搜索
    $('.project_main').on('click','.reset_search_list',function(){
    	window.localStorage.removeItem('searchList');
        historyJson = {};
        history = [];
    	$('.history_search').addClass('hide');
        $('.search_msg').removeClass('hide');
    });

    //搜素
    $('.project_main').on('click','.search_link',function(event){
        var search = $(this).text();
        window.localStorage.setItem('search',search);
        if(!historyJson[search]){
            history.unshift(search);
            window.localStorage.setItem('searchList',history.toString());
        }
        window.location.href = MODULE+'PublicJump/searchList';
        return false;
    });

    //前往搜索
    $('#search_form').submit(function(){
    	var search = $('[name="search"]').val().trim();
    	if(search == ''){
    		$.alert('搜索不能为空');
    		return false;
		}
        window.localStorage.setItem('search',search);
		if(!historyJson[search]){
			history.unshift(search);
			window.localStorage.setItem('searchList',history.toString());
		}
        window.location.href = MODULE+'PublicJump/searchList';
        return false;
    });

})